%option noyywrap nodefault case-insensitive
%{
#ifndef _YACC_TAB_HEADER_
#define _YACC_TAB_HEADER_
#include "../include/y.tab.h"
#endif
#ifndef _DATABASE_OPERATION_HEADER_
#define _DATABASE_OPERATION_HEADER_
#include "../include/operation.h"
#endif
%}

%%

create {
        return CREATE;}
select {
return SELECT;}

insert {return INSERT;}
update {return UPDATE;}
delete {return DELETE;}
show {return SHOW;}
desc {return DESC;}
databases {return DATABASES;}
database {return DATABASE;}
tables {return TABLES;}
table {return TABLE;}
into {return INTO;}
values {return VALUES;}
where {return WHERE;}
set {return SET;}
primary {return PRIMARY;}
foreign {return FOREIGN;}
use {return USE;}
as {return AS;}

key {return KEY;}


drop {return DROP;}
and {return AND;}
or {return OR;}

not {return NOT;} //  认为与！等价

from {return FROM;}
is {return IS;}
help  {return HELP;}
exit {return EXIT;}
null {return NUL;}
char {return CHAR;}
int {return INT;}
double {return DOUBLE;}
auto_increment {return AUTOINCREMENT;}

!= {yylval.cp = NE; return CP;}
> {yylval.cp = GT;  return CP;}
\< {yylval.cp = LT; return CP;}
>= {yylval.cp = GE;  return CP;}
\<= {yylval.cp = LE; return CP;}
== {yylval.cp = EQ;  return CP;}
! {printf("!\n"); return NOT;}



[a-zA-Z][a-zA-Z0-9_]+    {yylval.m_string = (char*)malloc(strlen(yytext));strcpy(yylval.m_string,yytext) ;printf("%s|\tas Identify!\n",yytext); return ID;}
[0-9][a-zA-Z0-9_]+ {printf("error:'%s' is not a symbol!\n",yytext);}


[+\-]?[1-9][0-9]*|0 {
    yylval.m_data = (struct Data *)malloc(sizeof(struct Data));
    yylval.m_data->value.i = atoi(yytext);
    yylval.m_data->type=  FIELD_INT;
    return DATA_INT;
    }
[+\-]?(([1-9][0-9]*)|0)"."[0-9]+  {
    yylval.m_data = (struct Data *)malloc(sizeof(struct Data));
    yylval.m_data->value.d = atof(yytext);
    printf("%lf| as double!\n",atof(yytext));
    yylval.m_data->type=  FIELD_DOUBLE;
    return DATA_DOUBLE;
    }


\“.*\" {
    yylval.m_data = (struct Data *)malloc(sizeof(struct Data));
    yytext = yytext+1;
    yylval.m_data->value.m_string = (char *)malloc(sizeof(char) * strlen(yytext));
    strcpy( yylval.m_data->value.m_string,yytext);
    yylval.m_data->value.m_string[strlen(yytext)-1] = '\0';
    yylval.m_data->type = FIELD_STRING;
    printf("read string %s",yytext);
    return DATA_STRING;
    }

; {printf("delimeter\n");return DELIMETER;}

"#".*

\n {printf("\nLiSQL> ");}

[ \t] {}

\* {printf("*\n");return yytext[0];}
\( {printf("\(\n");return yytext[0];}
\) {printf("\(\n");return yytext[0];}
\[ {printf("\(\n");return yytext[0];}
\] {printf("\(\n");return yytext[0];}
\{ {printf("\(\n");return yytext[0];}
\} {printf("\(\n");return yytext[0];}
, {printf("\(\n");return yytext[0];}
= {printf("=\n");return yytext[0];}
. {printf("\(\n");printf("%s\n",yytext);}

%%